package com.rt.schedulenew.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rt.schedulebase.dto.DictExamZoneDto;
import com.rt.schedulebase.entity.DictExamZone;
import com.rt.schedulebase.mapper.DictExamZoneMapper;
import com.rt.schedulenew.api.IDictExamZoneService;
import com.rt.schedulenew.utils.base.CommonUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DictExamZoneServiceImpl extends ServiceImpl<DictExamZoneMapper, DictExamZone> implements IDictExamZoneService {
    @Override
    public boolean insertSelective(DictExamZone dictExamZone) {
        return retBool(baseMapper.insert(dictExamZone));
    }

    @Override
    public boolean deleteByPrimaryKey(String key) {
        return retBool(baseMapper.deleteById(key));
    }

    @Override
    public boolean updateByPrimaryKeySelective(DictExamZone dictExamZone) {
        return retBool(baseMapper.updateById(dictExamZone));
    }

    @Override
    public DictExamZone selectByPrimaryKey(String key) {
        return baseMapper.selectById(key);
    }

    /**
     * ��ѯ��������б�
     *
     * @param dto
     * @return
     */
    @Override
    public List<DictExamZone> getList(DictExamZoneDto dto) {
        QueryWrapper<DictExamZone> qw = new QueryWrapper<>();
        Map<String, Object> map = new HashMap<>();
        map.put("ZONE_NAME", dto.getZoneName());
        map.put("DEPT_CODE", dto.getDeptCode());
        qw.allEq(map, false);
        if (StringUtils.isNotBlank(dto.getExamClass())) {
            qw.in("EXAM_CLASS", CommonUtil.split2List(dto.getExamClass()));
        }
        qw.orderByAsc("EXAM_CLASS", "SORT_NO");
        List<DictExamZone> list = baseMapper.selectList(qw);
        return list;
    }

    @Override
    public List<DictExamZone> getListAll() {
        return baseMapper.selectList(null);
    }

    @Override
    public boolean delete(DictExamZone dictExamZone) {
        UpdateWrapper<DictExamZone> uw = new UpdateWrapper<>();
        Map<String, Object> map = new HashMap<>();
        map.put("EXAM_CLASS", dictExamZone.getExamClass());
        map.put("ZONE_NAME", dictExamZone.getZoneName());
        uw.allEq(map, false);
        return retBool(baseMapper.delete(uw));
    }

    @Override
    public boolean update(DictExamZone dictExamZone) {
        UpdateWrapper<DictExamZone> uw = new UpdateWrapper<>();
        Map<String, Object> map = new HashMap<>();
        map.put("EXAM_CLASS", dictExamZone.getExamClass());
        map.put("ZONE_NAME", dictExamZone.getZoneName());
        uw.allEq(map, false);
        return retBool(baseMapper.update(dictExamZone, uw));
    }

    @Override
    public DictExamZone getInfo(DictExamZoneDto dto) {
        QueryWrapper<DictExamZone> qw = new QueryWrapper<>();
        Map<String, Object> map = new HashMap<>();
        map.put("EXAM_CLASS", dto.getExamClass());
        map.put("ZONE_NAME", dto.getZoneName());
        qw.allEq(map, false);
        return baseMapper.selectOne(qw);
    }
}
